package com.guoxin.concurrentprogramming.chapter2;

/**
 * @author guoxin
 * @date 2019/7/15
 */
public class ThreadGroupName implements Runnable {

    @Override
    public void run() {
        String groupAndName=Thread.currentThread().getThreadGroup().getName()+"-"+
                Thread.currentThread().getName();
        while(true){
            System.out.println("I'm "+groupAndName);
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        ThreadGroup tg = new ThreadGroup("PrintGroup");
        Thread t = new Thread(tg,new ThreadGroupName(),"T1");
        Thread t2 = new Thread(tg,new ThreadGroupName(),"T2");
        t.start();
        t2.start();
        System.out.println(tg.activeCount());
        tg.list();
    }
}
